Shorthand

object Shorthand

Shorthand extension functions for validating various types.

Author

fzzyhmstrs

Since

0.2.0

Samples

import me.fzzyhmstrs.fzzy_config.FC
import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.util.Expression
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validated
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedColor
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedIds
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedList
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedRegistry
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validatedTag
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import net.minecraft.item.SwordItem
import net.minecraft.registry.Registries
import net.minecraft.registry.tag.BlockTags
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
import java.awt.Color
import java.util.function.BiPredicate

fun main() { 
   //sampleStart 
   //shorthand validated Enum. the constant is the default value
val shorthandEnum = TestEnum.MORE.validated()

//Shorthand validated Color. The color values in the Color will be the default color components
val shorthandColor = Color(255, 255, 128, 255).validated()

//Shorthand validated Color from a base color int. The color values in the Color will be the default color components.
//In this example, the color does not accept transparency
val shorthandColorInt = 0xFF5500.validatedColor(false)

//Shorthand math Expression. This is directly in the Expression class itself, not in the Shorthand object
val shorthandMath = Expression.validated("x * 0.5", setOf('x'))

/////////////////////////////////

//example shorthand validated list. Shown is an identifier list. Note that identifier lists are actually string lists
val shorthandList = listOf(Identifier("stick")).validated(ValidatedIdentifier.ofRegistry(Identifier("stick"), Registries.ITEM))

//example Number-based shorthand list
val shorthandNumberList = listOf(1, 2, 5, 10).validated()

//example shorthand identifier list with automatic tag validation
val shorthandTagIdList = listOf(Identifier("white_bed")).validatedTag(ItemTags.BEDS)

//example shorthand identifier list with automatic registry validation
val shorthandRegistryIdList = listOf(Identifier("nether_star")).validatedRegistry(Registries.ITEM)

//example shorthand identifier list with automatic predicated registry validation
val shorthandPredicatedRegistryIdList = listOf(Identifier("stone_sword")).validatedRegistry(Registries.ITEM, BiPredicate { id, e -> e.value() is SwordItem })

//example shorthand identifier list with automatic list validation. The list should be complete and available at validation time
val shorthandListIdList = listOf(Identifier("arrow")).validatedList(listOf(Identifier("arrow"), Identifier("firework_rocket")))

//example shorthand validated Identifier using a tag for validation
val shorthandTagIds = BlockTags.AXE_MINEABLE.validatedIds()

//example shorthand validated Identifier using a registry for validation
val shorthandRegistryIds = Registries.ATTRIBUTE.validatedIds()

//example shorthand validated Identifier using a registry for validation
val shorthandPredicatedRegistryIds = Registries.ATTRIBUTE.validatedIds(BiPredicate { id, e -> id.namespace == FC.MOD_ID })

//example shorthand validated Identifier using a list for validation. The list should be complete and available at validation time
val shorthandListIds = listOf(Identifier("arrow"), Identifier("firework_rocket")).validatedIds()

//////////////////////////////////////

//example shorthand validated list. Shown is an identifier list. Note that identifier lists are actually string lists
val shorthandSet = setOf(Identifier("stick")).validated(ValidatedIdentifier.ofRegistry(Identifier("stick"), Registries.ITEM))

//example Number-based shorthand list
val shorthandNumberSet = setOf(1, 2, 5, 10).validated()

//example shorthand identifier list with automatic tag validation
val shorthandTagIdSet = setOf(Identifier("white_bed")).validatedTag(ItemTags.BEDS)

//example shorthand identifier list with automatic registry validation
val shorthandRegistryIdSet = setOf(Identifier("nether_star")).validatedRegistry(Registries.ITEM)

//example shorthand identifier list with automatic predicated registry validation
val shorthandPredicatedRegistryIdSet = setOf(Identifier("stone_sword")).validatedRegistry(Registries.ITEM, BiPredicate { id, e -> e.value() is SwordItem })

//example shorthand identifier list with automatic list validation. The list should be complete and available at validation time
val shorthandListIdSet = setOf(Identifier("arrow")).validatedList(listOf(Identifier("arrow"), Identifier("firework_rocket"))) 
   //sampleEnd
}

Functions

Link copied to clipboard

Shorthand validated Enum


Shorthand validated number List

Shorthand validated number Set

fun <T : Any> TagKey<T>.validated(): ValidatedTagKey<T>

Shorthand Validated TagKey, allowing any tag in the receiver tag's registry

Shorthand validated Identifier

fun Color.validated(transparent: Boolean = true): ValidatedColor

Shorthand validated Color

fun <T : Any> List<T>.validated(handler: Entry<T, *>): ValidatedList<T>

Shorthand validated List

fun <T : Any> Set<T>.validated(handler: Entry<T, *>): ValidatedSet<T>

Shorthand validated Set

Link copied to clipboard

Shorthand validated color, based on a color int

Link copied to clipboard

Shorthand Validated Identifier using the List for validation

Shorthand Validated Identifier using the Registry for validation

Shorthand Validated Identifier using the TagKey for validation

fun <T : Any> Registry<T>.validatedIds(predicate: BiPredicate<Identifier, RegistryEntry<T>>): ValidatedIdentifier

Shorthand Validated Identifier using the predicated Registry for validation

Link copied to clipboard
fun List<Identifier>.validatedList(list: List<Identifier>): ValidatedList<Identifier>

Shorthand Validated Identifier List, validated with a list

fun Set<Identifier>.validatedList(list: List<Identifier>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a list

Link copied to clipboard
fun <T : Any> List<Identifier>.validatedRegistry(registry: Registry<T>): ValidatedList<Identifier>

Shorthand Validated Identifier List, validated with a registry

fun <T : Any> Set<Identifier>.validatedRegistry(registry: Registry<T>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a registry

fun <T : Any> List<Identifier>.validatedRegistry(registry: Registry<T>, predicate: BiPredicate<Identifier, RegistryEntry<T>>): ValidatedList<Identifier>

Shorthand Validated Identifier List, validated with a predicated registry

fun <T : Any> Set<Identifier>.validatedRegistry(registry: Registry<T>, predicate: BiPredicate<Identifier, RegistryEntry<T>>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a predicated registry

Link copied to clipboard
fun List<Identifier>.validatedTag(tagKey: TagKey<*>): ValidatedList<Identifier>

Shorthand Validated Identifier List, validated with a tag

fun Set<Identifier>.validatedTag(tagKey: TagKey<*>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a tag